﻿XIncludeFile "Function.pb"

;==============================函数类型===============================

;==================================常数==================================
Enumeration
 #Style=1
 #Visible=2
 #Enabled=4
EndEnumeration

;==============================窗口结构==============================
Structure GdipLabel Extends PWnd
  Style.l
EndStructure

;================================函数===========================================

Procedure ILabelText(*Label.GdipLabel,Text.s)
  With *Label\Creat
    \Text\Text.s=Text
    TextColor=\Text\TextColor
    PeColor=\Text\PenColor
    If *Label\Enabled =3 
      TextColor=$AA505050
      PenColor= $50505050
    EndIf 
    GdipGetImageGraphicsContext(\ImageBack,@Graphics)
      GdipGraphicsClear(Graphics,0)
      GdipPathText(Graphics,Text,\Text\X,\Text\Y,\Text\Width,\Text\Height,\Text\FontName,\Text\FontSize,\Text\FontStyle,TextColor,PenColor,\Text\PenWidth,\Text\Align,\Text\Style)
    GdipDeleteGraphics(Graphics)
  EndWith
EndProcedure

Procedure ILabelSize(*Label.GdipLabel,Width,Height)
  *Label\Width =Width
  *Label\Height=Height
  *Label\Creat\Text\Width =Width
  *Label\Creat\Text\Height=Height
  GdipDisposeImage(*Label\Creat\ImageBack)
  *Label\Creat\ImageBack=GdipCreateImage(Width,Height)
  *Label\wText(*Label,*Label\Creat\Text\Text)
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

Procedure ILabelLoad(*Label.GdipLabel)
  *Label\wText(*Label,*Label\Creat\Text\Text)
EndProcedure

Procedure ILabelDraw(*Label.GdipLabel,*Gadget.PWnd,*cRect.RECT)

EndProcedure

Procedure ILabelEvent(*Label.GdipLabel,hWnd, uMsg, wParam, lParam)
  If *Label\Enabled =3
    ProcedureReturn  1
  EndIf 
  ProcedureReturn  1
EndProcedure

Procedure ILabelIsLoca(*Label.GdipLabel,hWnd,X,Y)
  X-*Label\X
  Y-*Label\Y
  If X>-1 And Y>-1 And X<*Label\Width And Y<*Label\Height  And *Label\Visible
    ProcedureReturn *Label
  EndIf 
EndProcedure

Procedure ILabelFree(*Label.GdipLabel)
  GdipDisposeImage(*Label\Draw)
  GdipDisposeImage(*Label\Creat\ImageBack)   ;绘制缓冲
  DeleteWindowList(*Label)
EndProcedure

Procedure GdipCreateLabel(*Hwnd.PWnd,X,Y,Width,Height,Text.s="",Style=6)  ;创建文本输入框
 *Label.GdipLabel=AddWindowList(@*Hwnd\Gadget,SizeOf(GdipLabel))
 *Label\Creat\ImageBack=GdipCreateImage(Width,Height)
 With *Label\Creat\Text
   \Text=Text
   \FontName="宋体"
   \FontSize=15
   \FontStyle=1
   \TextColor=$FF000000
   \Align= #GD_TextLineAlignCenter 
   \Style=4
   \X     = 0
   \Y     = 0
   \Width = Width
   \Height= Height
 EndWith
 With *Label
    \X=X
    \Y=Y
    \Width=Width
    \Height=Height
    \Visible=IsVal(Style,#Visible)
    \Enabled=(1-IsVal(Style,#Enabled))*3
    \Type=#Label
    \Style=IsVal(Style,1)
    \HostGadget=*Hwnd
    *Hwnd\NewGadget= *Label
    \wIsLoca=@ILabelIsLoca()
    \wLoad=@ILabelLoad()
    \wDraw=@ILabelDraw()
    \wEvent=@ILabelEvent()
    \wFree=@ILabelFree()
    \wSize=@ILabelSize()
    \wText=@ILabelText()   
  EndWith
  ProcedureReturn  *Label
EndProcedure


; IDE Options = PureBasic 4.30 (Windows - x86)
; CursorPosition = 100
; FirstLine = 66
; Folding = --
; EnableAsm
; EnableUnicode
; EnableXP
; DisableDebugger
; HideErrorLog
; CompileSourceDirectory